package com.myh.service.impl;

import com.myh.mapper.FileMapper;
import com.myh.pojo.File;
import com.myh.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author 莫耀华
 * @date 2020-08-23 17:39
 */
@Service
@Transactional
public class FileServiceImpl implements FileService {


    @Autowired
    private FileMapper fileMapper;

    @Override
    public List<File> findListByUid(Integer id) {
        return fileMapper.findListByUid(id);
    }

    @Override
    public void save(File file) {
        boolean b = file.getType().startsWith("image");
        file.setDownCounts(0);
        file.setUploadTime(new Date());
        file.setIsImg(b);
        fileMapper.save(file);
    }

    @Override
    public File findByFid(Integer id) {
        return fileMapper.findByFid(id);
    }

    @Override
    public void updateDownCountByFid(Integer id) {
        fileMapper.updateDownCountByFid(id);
    }

    @Override
    public void deleteByFid(Integer id) {
        fileMapper.deleteByFid(id);
    }

    @Override
    public List<Integer> findIdsMoreThanThe() {
        return fileMapper.findIdsMoreThanThe();
    }
}
